package com.szgr.baoyin.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.szgr.baoyin.R;

/**
 * Created by Jimbo on 2015/10/13.
 */
public class StationExpandableListAdapter extends BaseExpandableListAdapter {
    private Context mContext;
    public StationExpandableListAdapter(Context context){
        mContext = context;
    }
    @Override
    public int getGroupCount() {
        return 10;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return 1;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return null;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

    @Override
    public long getGroupId(int groupPosition) {
        return 0;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return 0;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        ParentHolder holder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_station_list_view,parent,false);
            holder = new ParentHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ParentHolder) convertView.getTag();

        if(isExpanded){
            holder.img_right.setImageResource(R.drawable.arrow_white_down);
        }else{
            holder.img_right.setImageResource(R.drawable.arrow_yellow_down);
        }
        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        ChildHolder holder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_station_child_list_view,parent,false);
            holder = new ChildHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ChildHolder) convertView.getTag();

        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

    private class ParentHolder {
        TextView tv_id;
        TextView tv_name;
        ImageView img_right;

        public ParentHolder(View view){
            tv_id = (TextView) view.findViewById(R.id.item_station_left);
            tv_name = (TextView) view.findViewById(R.id.item_station_text);
            img_right = (ImageView) view.findViewById(R.id.item_station_right);
        }
    }

    private class ChildHolder {
        TextView tv_left;
        TextView tv_right;

        public ChildHolder(View view){
            tv_left = (TextView) view.findViewById(R.id.phone_left);
            tv_right = (TextView) view.findViewById(R.id.phone_right);
        }
    }
}
